package com.example.demo;

import com.example.demo.model.MyList;
import com.example.demo.model.Student;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    @RequestMapping("/hello")//加上路由
    public String sayHello(){
        return "hello, Spring Boot";
    }

    @Value("${server.port}")
    private Integer port;

    @RequestMapping("/port")//设置路由
    public String myPort(){
        return "我的端口号为 : " + port;
    }

    @Value("${myKey1.key}")
    private String key;

    @RequestMapping("/myKey")//设置路由
    public String myKey(){
        return key;
    }

    //配置基本数据类型---->不是对象
    @Value("${myString}")
    private String myString;

    @Value("${boolean.value}")
    private boolean flg;

    @Value("${int.value}")
    private int cnt;

    @Value("${float.value}")
    private float fla;

    @Value("${null.value}")
    private String Null;

    @RequestMapping("/dataType")
    public String myString(){
        return "myString" + myString + " boolean.value " + flg
                + " int.value " + cnt + " float.value " + fla +
                " null.value : " + Null;
    }

    //注入集合
    @Autowired
    private MyList myList;
    @RequestMapping("/myList")
    public String myList(){
        return "Hi " + "   下标为0的值  " + myList.getDbtype().get(0) +
                "   myList集合大小 : " + myList.getDbtype().size();
    }

    //注入对象
    @Autowired
    private Student student;

    @RequestMapping("/student")
    public String myString2(){
        return "Hi " + student.toString();
    }


    //1.得到日志对象--->TestController的日志对象
    //使用slf4j
    private static Logger logger = LoggerFactory.getLogger(TestController.class);

    @RequestMapping("/hi")
    public String SayHi(){
        //使用日志对象提供的方法进行输出日志
        logger.trace("Hi,i am trace");//追踪(痕迹)日志
        logger.debug("Hi,Spring Boot Log.");//调试日志
        logger.info("Hi,SpringBoot,Logger");//普通信息
        logger.warn("Hi,I,am warn");//警告信息
        logger.error("Hi,I am error");//报错
        //fatal程序终止的时候才会看到
        return "hi,SpringBoot";
    }


}
